package xscjglxt;


import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class MainApp {
    public static void main(String[] args) {
        TreeSet<Per> tree= new TreeSet<>(new Comparator<Per>(){
            @Override
            public int compare(Per o1,Per o2){
                //按照学号从小到大排序
                //return Integer.valueOf(o1.getNumber()-Integer.valueOf(o2.getNumber()));
                //按照成绩从小到大排序
                return o1.getScore()-o2.getScore();
            }
        });

        tree.add(new Per("刘备","1001",90));
        tree.add(new Per("关羽","1008",70));
        tree.add(new Per("张飞","1003",10));
        tree.add(new Per("诸葛亮","1009",80));
        tree.add(new Per("刘备","1002",60));
        System.out.println("最低分是"+tree.first());
        System.out.println("最高分是"+tree.last());

        //不及格学生
        SortedSet<Per> sortedSet=tree.headSet(new Per("aa","8998",60));
        for (Per p:sortedSet){
            System.out.println(p);
        }
        //求平均分
        double avg=tree.stream().mapToDouble(a->a.getScore()).average().getAsDouble();
        System.out.println("平均分是"+avg);
        System.out.println("求60分到80 分的学生------");
        SortedSet sortedSet1=tree.subSet(new Per("aa","000",60),new Per("bb","000",80));
        System.out.println(sortedSet1);

        //求60分到80 分的学生  区间，左右是否包含通过  两个参数  决定
    }
}